<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class upgrade {

    public function check_upgrade($db, $config, $ver) {
        global $log;
        $db_minor = $ver["db"]["minor"];
        $db_minor++;
        $upgraded = false;
        $log->print_message("Upgrade check!\n");
        while (file_exists("sql/upgrade_{$db_minor}.sql")) {
            $patch = file_get_contents("sql/upgrade_{$db_minor}.sql");
            $lines = explode("\n", $patch);
            foreach ($lines as $line) {
                if (!empty($line))
                    $r = $db->sql($line);
            }
            $upgraded = true;
            $db_minor++;
        }
        if (!$upgraded)
            return false;
        $db_minor--;
        die("Database upgraded to {$db_minor}!");
    }

}

?>
